package com.wenqian.server.config;

import java.io.InputStream;
import java.util.Properties;

public class ServerConfig {
    private Properties properties = new Properties();

    public ServerConfig(String resourceName) {
        try (InputStream input = getClass().getClassLoader().getResourceAsStream(resourceName)) {
            if (input == null) {
                System.err.println("Sorry, unable to find " + resourceName);
                // 使用默认值
                properties.setProperty("server.port", "8080");
                properties.setProperty("server.webroot", "www");
                properties.setProperty("server.poolsize", "10");
                return;
            }
            properties.load(input);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public int getPort() {
        return Integer.parseInt(properties.getProperty("server.port"));
    }

    public String getWebRoot() {
        return properties.getProperty("server.webroot");
    }

    public int getPoolSize() {
        return Integer.parseInt(properties.getProperty("server.poolsize"));
    }
}